#ifndef __SOCKET_IO_H__
#define __SOCKET_IO_H__ 1

#include "sample_io.h"

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

class CSocketIO : public ISampleIO
{
public:
	CSocketIO(NAudioFormats::SStreamInfo pStreamInfo);
	virtual ~CSocketIO();

	/* START methods inherited by ISampleIO */
	virtual int init(CPropertiesReader *pConfig);
	virtual int destroy();

	virtual int read(void** pData, EAction& pAction, int pTimeout = 1000);
	virtual int write(void* pData, const EAction& pAction, int pLength);

	virtual NAudioFormats::SStreamInfo getStreamInfo();
	/* END methods inherited by ISampleIO */

private:
	static const std::string sIniSection;

	//unsigned int mBytePerSample;
	NAudioFormats::SStreamInfo mStreamInfo;
	int mServerSocket;
	int mSocket;
	struct sockaddr_in mServerAddress;
	struct sockaddr_in mAddress;
	char* mByteBuf;
	int mByteCount;

	CSocketIO(const CSocketIO& );
	CSocketIO& operator=(const CSocketIO& );

	uint32_t fullRecv(void *pBuf, uint32_t pLength);
	int fullSend(const void *pBuf, int pLength);

	void* getByteBuffer(int pByteLength);
};

#endif /* __SOCKET_IO_H__ */
